package com.dys.testsimplefactory;

/**
 * @className: com.dys.testsimplefactory.PetStore
 * @description: 宠物店-->工厂类：解决大量对象创建的问题
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/07/21 下午2:45
 */
public class PetStore {

    /**
     * 多态的应用：返回值类型是父类类型，返回的可以是任意子类型
     *
     * @param name 宠物名字
     * @return 任意子类类型
     */
    public static Animal getAnimal(String name) {
        Animal animal = null;
        if ("猫".equals(name)) {
            animal = new Cat();
        }
        if ("狗".equals(name)) {
            animal = new Dog();
        }
        return animal;
    }
}
